clear all

*Define global path for replication package
global path "~/Dropbox/IT_Revolution/Replication_package/JPE submission"

global path_rawdata "$path/Raw_data"
global path_cleandata "$path/Clean_data"
global path_output "$path/Output"


* Step 1: Data construction for 2012
********************************************************************************

*** Prepare Beruf data
use "$path_rawdata/beruf_task_data_Germany.dta", clear

collapse (mean) wgt_shr_t1-wgt_shr_t5, by(beruf_gr)
rename beruf_gr occ

save "$path_cleandata/beruf_data.dta", replace

*** Prepare Germany data for 2012
use "$path_rawdata/2012_BIBB.dta", clear

*name variables
rename (Zpalter az Des2012 Bula S1) (age hours sweight bula s1)
rename (EB92g F318 F319) (occ computer internet)

*select sample
keep if s1 == 1
keep if age >= 17 & age <= 64

*keep west germany
keep if bula <= 11

*drop part-time (defined as less than 35 hours)
drop if hours <= 35
drop if hours > 90
drop if hours ==.

keep occ age computer internet sweight

gen year = 2012

foreach var of varlist internet computer  {
	gen D`var' = (`var' == 1)
	drop `var'
}
gen emp = 1
	
*data for all workers
preserve 
	collapse (mean) Dinternet Dcomputer (sum) emp [aw = sweight], by(year occ)

	merge m:1 occ using "$path_cleandata/beruf_data.dta"
	drop if _merge < 3

	gen index_anal_old = wgt_shr_t1+wgt_shr_t2
	drop wgt_shr_t1-_merge
	
	reshape wide Dinternet Dcomputer, i(occ index_anal_old) j(year)

	save "$path_cleandata/BIBB_for_regs.dta", replace
restore

*data by worker cohort
preserve 
	gen ind_young = (age <= 40)
	
	collapse (mean) Dinternet Dcomputer (sum) emp [aw = sweight], by( year occ ind_young )

	merge m:1 occ using "$path_cleandata/beruf_data.dta"
	drop if _merge < 3

	gen index_anal_old = wgt_shr_t1+wgt_shr_t2
	drop wgt_shr_t1-_merge
	
	reshape wide Dinternet Dcomputer, i(occ index_anal_old ind_young) j(year)

	save "$path_cleandata/BIBB_for_regs_age.dta", replace
restore



*Step 2: Plot share of intensive internet and computer usage by occupation cognitive intensity
********************************************************************************

use "$path_cleandata/BIBB_for_regs_age.dta", clear

append using "$path_cleandata/BIBB_for_regs.dta"

replace ind_young = 2 if ind_young == .

xtile pct_analytical = index_anal_old, nq(100) 
	   
twoway (lpoly Dinternet2012 pct_analytical if ind_young == 0 , lc(blue) lp(dash)  ) ///
	   (lpoly Dinternet2012 pct_analytical if ind_young == 1 , lc(red) lp(dash_dot ) ) ///
	   (lpoly Dinternet2012 pct_analytical if ind_young == 2 , lc(black)), ///
	   xtitle("Percentile of occupation cognitive intensity", size(small)) ytitle("Percentage of individuals" "intensively using internet on the job, 2012", size(small)) ///
       title("Panel A: Intensive Internet Use by Occupation") ///
	  legend(row(1) col(3) lab(1 "Older") lab(2 "Younger") lab(3 "All") order(- "Generation:" 1 2 3)) scheme(s1color) name(internet_use3)   
	   
twoway (lpoly Dcomputer2012 pct_analytical if ind_young == 0 , lc(blue) lp(dash)  ) ///
	   (lpoly Dcomputer2012 pct_analytical if ind_young == 1 , lc(red) lp(dash_dot ) ) ///
	   (lpoly Dcomputer2012 pct_analytical if ind_young == 2 , lc(black)), ///
	   xtitle("Percentile of occupation cognitive intensity", size(small)) ytitle("Percentage of individuals" "intensively using computers on the job, 2012", size(small)) ///
       title("Panel B: Intensive Computer Use by Occupation") ///
	   legend(row(1) col(3) lab(1 "Older") lab(2 "Younger") lab(3 "All") order(- "Generation:" 1 2 3)) scheme(s1color) name(computer_use3)   
	
graph combine internet_use3 computer_use3, scheme(s1color) xsize(8)
graph export "$path_output/technology_use.png", as(png) replace
graph export "$path_output/technology_use.eps", as(eps) replace
